/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ctrl;

import com.cxhd.lis.service.ZkStandardService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;
import java.util.Map;

/**
 *
 * @author 52461
 */
@ControllerBind(controllerKey = "/view/zk/zk_value")
public class ZkStandardCtrl extends Controller {
    
    private ZkStandardService zss = new ZkStandardService();
    
    public void index() {
        render("/view/zk/zk_value.jsp");
    }

    //获取批号
    public void getPh() {
        renderJson(Db.find("select * from zk_reagent where DEVICE = '" + getPara("device") + "'"));
    }
    
    public void getDeviceStandard() {
        
        String zk_reagent_pk = getPara("zk_reagent_pk");
        String device = getPara("device");
        String sql = "select b.*,a.PK as ZK_OBJECT_PK,c.TESTID FROM zk_object a LEFT JOIN zk_standard b on a.PK = b.ZK_OBJECT_PK LEFT JOIN lis_testdescribe c on a.TESTPK=c.PK WHERE (b.ZK_REAGENT_PK='" + zk_reagent_pk + "' or b.ZK_REAGENT_PK is null) and a.DEVICEID='" + device + "' ";
         System.out.println(sql);
        List<Record> list = Db.find(sql);
        
        if (list == null || list.isEmpty()) {
            
            sql = " select a.PK as ZK_OBJECT_PK,DEVICEID,c.TESTID,DEVICEPK,TESTPK from zk_object a left join lis_testdescribe c on a.TESTPK=c.PK  where DEVICEID ='" + device + "' ";
            System.out.println(sql);
            list = Db.find(sql);
            
        }
        renderJson(list);
        
    }
    
    public void saveDeviceStandard() {
        List<Map<String, String>> list = new Gson().fromJson(getPara("data"), new TypeToken<List<Map<String, String>>>() {
        }.getType());
        if (zss.save(list,this)) {
            renderText("true");
        } else {
            renderText("false");
        }
        
    }
}
